
package ro.ase.catalog.security.dao.hibernate;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import ro.ase.catalog.beans.Token;
import ro.ase.catalog.dao.hibernate.GenericDAOImpl;
import ro.ase.catalog.security.dao.ITokenDAO;

import java.util.List;


@SuppressWarnings("unchecked")
public class TokenDAOImpl extends GenericDAOImpl<Token, Integer> implements ITokenDAO {


    public Token findByKey(String key) {
        DetachedCriteria criteria = DetachedCriteria.forClass(Token.class);
        criteria.add(Expression.eq("key", key ));

        List<Token> list = getHibernateTemplate().findByCriteria(criteria);
        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

}
